<?php
namespace core;


class Request {
    private string $method; //请求方法
    private string $uri; //请求路径
    private array $queryParams; //get 数据
    private array $postData; //post 数据

    private array $params = []; //路由参数


    public function __construct() {
        $this->method = $_SERVER['REQUEST_METHOD'];
        $this->uri = $_SERVER['REQUEST_URI'];
        $this->queryParams = $_GET;
        $this->postData = $_POST;
    }

    public function getMethod(): string {
        return $this->method;
    }

    public function getUri(): string {
        return explode('?', $this->uri, 2)[0];
    }

    public function getQueryParams(): array {
        return $this->queryParams;
    }

    public function getPostData(): array {
        return $this->postData;
    }

    public function getParams(): array {
        return $this->params;
    }

    public function setParams(array $val): void {
        $this->params = $val;
    }

    public function getParam(string $key) {
        return $this->params[$key];
    }
}
